package com.ssyt.blog.core.sys.dao;

import org.springframework.stereotype.Repository;

import com.ssyt.blog.core.common.BaseDao;
import com.ssyt.blog.core.common.PageModel;
import com.ssyt.blog.core.sys.entity.User;

@Repository
public class UserDao extends BaseDao<User, Integer> {

	public void addUser(User user) {
		save(user);
	}

	public User load(Integer id) {
		return super.load(id);
	}

	public User login(String code, String password) {
		User user = uniqueEntityByHql("FROM User WHERE code=? AND password=?",
				code, password);
		return user;
	}

	public Integer register(User user) {
		return save(user);
	}

	public PageModel<Object[]> getUserList(Integer pageNo) {
		return pageMultiPropertyByHql(pageNo, 8,
				"SELECT id,name,code FROM User");
	}

	public void deleteUserInfo(Integer id) {
		User user = load(id);
		delete(user);
	}
}
